package cn.com.surker.production.entity.vo;

import cn.com.surker.enums.ICodeDescEnum;
import cn.com.surker.enums.production.invoice.BackTypeEnum;
import cn.com.surker.enums.production.invoice.ShipTypeEnum;
import cn.com.surker.enums.production.invoice.TranTypeEnum;
import cn.com.surker.excel.ExcelCell;
import cn.com.surker.production.entity.InvoiceHandle;
import cn.com.surker.util.DateUtil;
import cn.com.surker.util.MathUtils;
import cn.com.surker.util.StringUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * 转料详情操作
 *
 * @author luotao
 * @date 2024/10/22
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class InvoiceHandleDetail extends InvoiceHandle {

	/**
	 * 处理方式
	 */
	private String operateTypeTxt;

	public String getOperateTypeTxt() {
		Integer operateType = getOperateType();
		ShipTypeEnum anEnum = ICodeDescEnum.getEnum(ShipTypeEnum.class, operateType);
		if (anEnum != null) {
			return anEnum.getDescription();
		} else {
			return "";
		}
	}

	/**
	 * 分料类型
	 */
	private String tranTypeTxt;

	public String getTranTypeTxt() {
		Integer tranType = getTranType();
		TranTypeEnum anEnum = ICodeDescEnum.getEnum(TranTypeEnum.class, tranType);
		if (anEnum != null) {
			return anEnum.getDescription();
		} else {
			return "";
		}
	}

	/**
	 * 退料类型
	 */
	private String reTypeTxt;

	public String getReTypeTxt() {
		Integer reType = getReType();
		BackTypeEnum anEnum = ICodeDescEnum.getEnum(BackTypeEnum.class, reType);
		if (anEnum != null) {
			return anEnum.getDescription();
		} else {
			return "";
		}
	}

	/**
	 * 是流入还是流程;查询的source_invoice_id为流出;
	 * target_invoice_id 为流入
	 */
	private String inOutTxt;

	/**
	 * 退货单的已处理方量
	 */
	private Double backTranStere;

	public Double getBackTranStere() {
		if (backTranStere == null) {
			backTranStere = 0d;
		}
		return backTranStere;
	}

	/**
	 * 退货单的剩余处理方量
	 */
	private Double backRemainStere;

	public Double getBackRemainStere() {
		Double operateStere = getWeightStere();
		backRemainStere = MathUtils.subtract(operateStere, backTranStere);
		if (backRemainStere == null) {
			backRemainStere = 0d;
		}
		return backRemainStere;
	}

	/**
	 * 合同编号
	 */
	private String conCode;

	/**
	 * 合同名称
	 */
	@ExcelCell(value = "工程名称", sort = 2)
	private String conName;

	/**
	 * 客户名称
	 */
	private String clientName;

	/**
	 * 强度等级
	 */
	@ExcelCell(value = "砼强度", sort = 4)
	private String strengthName;

	/**
	 * 塌落度
	 */
	private String slumps;

	/**
	 * 特性要求
	 */
	@ExcelCell(value = "特性要求", sort = 5)
	private String tech;

	/**
	 * 浇筑方式
	 */
	@ExcelCell(value = "浇筑方式", sort = 9)
	private String castModelName;

	/**
	 * 泵送设备
	 */
	private String pumpDeviceName;

	/**
	 * 泵送类型
	 */
	private String pumpTypeName;

	/**
	 * 泵送规格
	 */
	private String pumpNormName;

	/**
	 * 源发货单编号
	 */
	@ExcelCell(value = "发货单编号", sort = 1)
	private String sourceInvoiceCode;

	/**
	 * 目标发货单号
	 */
	private String targetInvoiceCode;

	/**
	 * 发货单发货时间
	 */
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private Date sourInvProTime;

	/**
	 * 施工部位
	 */
	@ExcelCell(value = "施工部位", sort = 3)
	private String site;

	/**
	 * 车辆编号
	 */
	@ExcelCell(value = "车辆编号", sort = 6)
	private String carCode;

	/**
	 * 车牌号
	 */
	@ExcelCell(value = "车牌号", sort = 7)
	private String carNo;

	/**
	 * 发货单的发货方量
	 */
	/*private Double sendStere;*/

	/**
	 * 发货单的生产方量
	 */
	private Double proStere;

	/**
	 * 前端用的样式
	 */
	private String typeClass;

	public String getTypeClass() {
		typeClass = "info";
		Integer operateType = getOperateType();
		if (ShipTypeEnum.BACK_SCRAP_WEIGHT.getCode().equals(operateType)) {
			//	退砼
			typeClass = "primary";
		} else if (ShipTypeEnum.INVOICE_SCRAP.getCode().equals(operateType)) {
			//	作废
			typeClass = "danger";
		} else {
			String inOutTxt = getInOutTxt();
			if (StringUtils.isNotBlank(inOutTxt)) {
				if (inOutTxt.equals("流出")) {
					// 转出
					typeClass = "warning";
				} else if (inOutTxt.equals("流入")) {
					typeClass = "success";
				}
			}
		}
		return typeClass;
	}

	/**
	 * 原发货的是否累计
	 */
	private Integer isAdd;

	/**
	 * 目标车辆
	 */
	private String tarCarCode;

	//	目标合同
	private String tarConName;

	//	目标施工部位
	private String tarSite;

	//	目标强度等级
	private String tarStrengthName;


}